package cn.iocoder.yudao.module.erp.controller.admin.planinfo;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
import cn.iocoder.yudao.module.crm.dal.mysql.product.CrmProductCategoryMapper;
import cn.iocoder.yudao.module.crm.service.product.CrmProductCategoryService;
import cn.iocoder.yudao.module.erp.controller.admin.contractinfo.vo.ContractInfoRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.planinfo.vo.*;
import cn.iocoder.yudao.module.erp.dal.dataobject.contractinfo.ContractInfoDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.customerinfo.CustomerInfoDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.monthplaninfo.MonthPlanInfoDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.planinfo.PlanInfoDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.mysql.contractinfo.ContractInfoMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.customerinfo.CustomerInfoMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.monthplaninfo.MonthPlanInfoMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductCategoryMapper;
import cn.iocoder.yudao.module.erp.service.customerinfo.CustomerInfoService;
import cn.iocoder.yudao.module.erp.service.planinfo.PlanInfoService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductCategoryService;
import cn.iocoder.yudao.module.system.enums.common.SexEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Parameters;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import org.springframework.web.multipart.MultipartFile;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;


@Tag(name = "管理后台 - 每日计划")
@RestController
@RequestMapping("/lng/plan-info")
@Validated
public class PlanInfoController {

    @Resource
    private PlanInfoService planInfoService;

    @Resource
    private CustomerInfoService customerInfoService;


    @Resource
    private CustomerInfoMapper customerInfoMapper;
    @Resource
    private ContractInfoMapper contractInfoMapper;

    @Resource
    private CrmProductCategoryService crmproductCategoryService;

    @Resource
    private ErpProductCategoryService erpProductCategoryService;

    @Resource
    private CrmProductCategoryMapper crmProductCategoryMapper;

    @Resource
    private ErpProductCategoryMapper erpProductCategoryMapper;

    @Resource
    private MonthPlanInfoMapper monthPlanInfoMapper;



    @PostMapping("/create")
    @Operation(summary = "创建每日计划")
/*    @PreAuthorize("@ss.hasPermission('lng:plan-info:create')")*/
    public CommonResult<Long> createPlanInfo(@Valid @RequestBody PlanInfoSaveReqVO createReqVO) {
        return success(planInfoService.createPlanInfo(createReqVO));
    }


    @GetMapping("/calculatePlanInfoCount")
    @Operation(summary = "重新计算每日计划量")
    public CommonResult<Boolean> calculatePlanInfoCount() {
        //得到每日计划


        return success(planInfoService.calculatePlanInfoCount());
    }


    @PostMapping("/finishPlanInfo")
    @Operation(summary = "结算")
    /*    @PreAuthorize("@ss.hasPermission('lng:plan-info:create')")*/
    public CommonResult<Long> finishPlanInfo(@Valid @RequestBody PlanInfoFinishReqVO createReqVO) {
        return success(planInfoService.finishPlanInfo(createReqVO));
    }


    @GetMapping("/get-import-template")
    @Operation(summary = "获得导入用户模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 手动创建导出 demo
        List<PlanInfoImportVO> list = Arrays.asList(
               /* PlanInfoImportVO.builder().username("yunai").deptId(1L).email("yunai@iocoder.cn").mobile("15601691300")
                        .nickname("芋道").status(CommonStatusEnum.ENABLE.getStatus()).sex(SexEnum.MALE.getSex()).build(),
                PlanInfoImportVO.builder().username("yuanma").deptId(2L).email("yuanma@iocoder.cn").mobile("15601701300")
                        .nickname("源码").status(CommonStatusEnum.DISABLE.getStatus()).sex(SexEnum.FEMALE.getSex()).build()*/
        );
        // 输出
        ExcelUtils.write(response, "每日计划导入模板.xls", "每日计划列表", PlanInfoImportVO.class, list);
    }


    @PostMapping("/import")
    @Operation(summary = "导入每日计划")
    @Parameters({
            @Parameter(name = "file", description = "Excel 文件", required = true),
            @Parameter(name = "updateSupport", description = "是否支持更新，默认为 false", example = "true")
    })
   /* @PreAuthorize("@ss.hasPermission('system:user:import')")*/
    public CommonResult<PlanImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
                                                      @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
        List<PlanInfoImportVO> list = ExcelUtils.read(file, PlanInfoImportVO.class);
        return success(planInfoService.importPlanList(list, updateSupport));
    }

    @PutMapping("/update")
    @Operation(summary = "更新每日计划")
    @PreAuthorize("@ss.hasPermission('lng:plan-info:update')")
    public CommonResult<Boolean> updatePlanInfo(@Valid @RequestBody PlanInfoSaveReqVO updateReqVO) {
        planInfoService.updatePlanInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除每日计划")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('lng:plan-info:delete')")
    public CommonResult<Boolean> deletePlanInfo(@RequestParam("id") Long id) {
        planInfoService.deletePlanInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得每日计划")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('lng:plan-info:query')")
    public CommonResult<PlanInfoRespVO> getPlanInfo(@RequestParam("id") Long id) {
        PlanInfoDO planInfo = planInfoService.getPlanInfo(id);
        PlanInfoRespVO plan= BeanUtils.toBean(planInfo, PlanInfoRespVO.class);
        CustomerInfoDO buyCustomer=customerInfoMapper.selectById(plan.getBuyCustomerId());

        CustomerInfoDO saleCustomer=customerInfoMapper.selectById(plan.getSaleCustomerId());
        if(buyCustomer!=null){
            plan.setBuyCustomerName(buyCustomer.getName());
        }

        if(saleCustomer!=null){
            plan.setSaleCustomerName(saleCustomer.getName());
        }



      /*  //设置下简称
        List<CrmProductCategoryDO> list=crmProductCategoryMapper.selectList();
        //得到一级
        List<CrmProductCategoryDO> leverOneList=list.stream().filter(e->e.getParentId()==0L).collect(Collectors.toList());
        //得到二级
        List<Long> pIds=leverOneList.stream().map(CrmProductCategoryDO::getId).collect(Collectors.toList());
        List<CrmProductCategoryDO> leverTwoList=list.stream().filter(e->pIds.contains(e.getParentId())).collect(Collectors.toList());
        //得到三级
        List<Long> tIds=leverTwoList.stream().map(CrmProductCategoryDO::getId).collect(Collectors.toList());
        Map<Long, String> mps = leverTwoList.stream()
                .collect(Collectors.toMap(CrmProductCategoryDO::getId, CrmProductCategoryDO::getName));
        List<CrmProductCategoryDO> leverThreeList=list.stream().filter(e->tIds.contains(e.getParentId())).collect(Collectors.toList());
        leverThreeList.stream().forEach(pc->{
            pc.setShortName(mps.get(pc.getParentId()));
        });
        crmProductCategoryMapper.updateBatch(leverThreeList);


        //下载点
        //设置下简称
        List<ErpProductCategoryDO> erplist=erpProductCategoryMapper.selectList();
        //得到一级
        List<ErpProductCategoryDO> leverOneList2=erplist.stream().filter(e->e.getParentId()==0L).collect(Collectors.toList());
        //得到二级
        List<Long> pIds2=leverOneList2.stream().map(ErpProductCategoryDO::getId).collect(Collectors.toList());
        List<ErpProductCategoryDO> leverTwoList2=erplist.stream().filter(e->pIds2.contains(e.getParentId())).collect(Collectors.toList());
        //得到三级
        List<Long> tIds2=leverTwoList2.stream().map(ErpProductCategoryDO::getId).collect(Collectors.toList());
        Map<Long, String> mps2 = leverTwoList2.stream()
                .collect(Collectors.toMap(ErpProductCategoryDO::getId, ErpProductCategoryDO::getName));
        List<ErpProductCategoryDO> leverThreeList2=erplist.stream().filter(e->tIds2.contains(e.getParentId())).collect(Collectors.toList());
        leverThreeList2.stream().forEach(pc->{
            pc.setShortName(mps2.get(pc.getParentId()));
        });
        erpProductCategoryMapper.updateBatch(leverThreeList2);*/


        return success(plan);
    }


    @Resource(name = "crmProductCategoryMapper")
    private CrmProductCategoryMapper productCategoryMapper;

    @GetMapping("/page")
    @Operation(summary = "获得每日计划分页")
    @PreAuthorize("@ss.hasPermission('lng:plan-info:query')")
    public CommonResult<PageResult<PlanInfoRespVO>> getPlanInfoPage(@Valid PlanInfoPageReqVO pageReqVO) {
        PageResult<PlanInfoDO> pageResult = planInfoService.getPlanInfoPage(pageReqVO);


        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(PageResult.empty(pageResult.getTotal()));
        }
        List<PlanInfoRespVO> rlist=buildList(pageResult.getList(),"");
        PageResult<PlanInfoRespVO> rpage= BeanUtils.toBean(pageResult, PlanInfoRespVO.class);
        rpage.setList(rlist);

        return success(rpage);
    }




    public List<PlanInfoRespVO> buildList(List<PlanInfoDO> list,String flag){
        if (CollUtil.isEmpty(list)) {
            return null;
        }
        //月度计划
        List<Long> monthIds=list.stream().map(PlanInfoDO::getCompanyId).filter(Objects::nonNull).collect(Collectors.toList());
        List<MonthPlanInfoDO> monthList = monthPlanInfoMapper.selectList(new LambdaQueryWrapperX<MonthPlanInfoDO>().select(MonthPlanInfoDO::getId,MonthPlanInfoDO::getName)
                .in(MonthPlanInfoDO::getId,monthIds));

        Map<Long,MonthPlanInfoDO> monthMap=monthList.stream().collect(Collectors.toMap(MonthPlanInfoDO::getId, e -> e));

        // 客户信息
        List<Long> customerIds=list.stream().flatMap(item-> Stream.of(item.getBuyCustomerId(),item.getSaleCustomerId())).collect(Collectors.toList());
        List<CustomerInfoDO> customerList = customerInfoService.getCustomerListIds(customerIds);

        Map<Long,CustomerInfoDO> customerMap=customerList.stream().collect(Collectors.toMap(CustomerInfoDO::getId, e -> e));
        //  return success(BeanUtils.toBean(pageResult, PlanInfoRespVO.class));

        //合同信息
        List<Long> contractIds=list.stream().flatMap(item-> Stream.of(item.getBuyContractId(),item.getSaleContractId())).collect(Collectors.toList());
        List<ContractInfoDO> contractInfoDOList = contractInfoMapper.selectList(new LambdaQueryWrapperX<ContractInfoDO>().in(ContractInfoDO::getId,contractIds));

        Map<Long,ContractInfoDO> contractMap=contractInfoDOList.stream().collect(Collectors.toMap(ContractInfoDO::getId, e -> e));

        Map<Long, CrmProductCategoryDO> upMap =new HashMap<>();
        Map<Long, ErpProductCategoryDO> downloadMap =new HashMap<>();
        if(StringUtils.isBlank(flag)||flag.equals("sale")){
            Set<Long> upIds=convertSet(list, PlanInfoDO::getUpId);
            if(upIds!=null&&upIds.size()>0){
                List<CrmProductCategoryDO> uplist= productCategoryMapper.selectBatchIds(upIds);
                upMap=uplist.stream().collect(Collectors.toMap(CrmProductCategoryDO::getId, e -> e));
            }
        }

        if(StringUtils.isBlank(flag)||flag.equals("buy")){
            Set<Long> downloadIds=convertSet(list, PlanInfoDO::getDownloadId);
            if(downloadIds!=null&&downloadIds.size()>0){
                List<ErpProductCategoryDO> dllist= erpProductCategoryMapper.selectBatchIds(downloadIds);
                downloadMap=dllist.stream().collect(Collectors.toMap(ErpProductCategoryDO::getId, e -> e));
            }
        }
        List<PlanInfoRespVO> rpage= BeanUtils.toBean(list, PlanInfoRespVO.class);

        for(PlanInfoRespVO plan:rpage){
            MapUtils.findAndThen(monthMap, plan.getCompanyId(), cus -> plan.setCompanyName(cus.getName()));

            MapUtils.findAndThen(customerMap, plan.getBuyCustomerId(), cus -> plan.setBuyCustomerName(cus.getName()));
            MapUtils.findAndThen(customerMap, plan.getSaleCustomerId(), cus -> plan.setSaleCustomerName(cus.getName()));

            MapUtils.findAndThen(contractMap, plan.getBuyContractId(), cus -> plan.setBuyContractName(cus.getName()));

            MapUtils.findAndThen(contractMap, plan.getSaleContractId(), cus -> plan.setSaleContractName(cus.getName()));

            MapUtils.findAndThen(upMap, plan.getUpId(),
                    l -> plan.setUpName(l.getShortName()));

            MapUtils.findAndThen(downloadMap, plan.getDownloadId(),
                    l -> plan.setDownloadName(l.getShortName()));
        }
        return rpage;
    }



    @GetMapping("/sale-info-page")
    @Operation(summary = "获得销售管理分页")
    @PreAuthorize("@ss.hasPermission('erp:sale:query')")
    public CommonResult<PageResult<PlanInfoRespVO>> getSalePlanInfoPage(@Valid PlanInfoPageReqVO pageReqVO) {
        PageResult<PlanInfoDO> pageResult = planInfoService.getPlanInfoPage(pageReqVO);


        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(PageResult.empty(pageResult.getTotal()));
        }
        List<PlanInfoRespVO> rlist=buildList(pageResult.getList(),"sale");
        PageResult<PlanInfoRespVO> rpage= BeanUtils.toBean(pageResult, PlanInfoRespVO.class);
        rpage.setList(rlist);
        return success(rpage);

        // 客户信息
      /*  List<Long> customerIds=pageResult.getList().stream().flatMap(item-> Stream.of(item.getBuyCustomerId(),item.getSaleCustomerId())).collect(Collectors.toList());
        List<CustomerInfoDO> customerList = customerInfoService.getCustomerListIds(customerIds);

        Map<Long,CustomerInfoDO> customerMap=customerList.stream().collect(Collectors.toMap(CustomerInfoDO::getId, e -> e));
        //  return success(BeanUtils.toBean(pageResult, PlanInfoRespVO.class));
//月度计划
        List<Long> monthIds=pageResult.getList().stream().map(PlanInfoDO::getCompanyId).filter(Objects::nonNull).collect(Collectors.toList());
        List<MonthPlanInfoDO> monthList = monthPlanInfoMapper.selectList(new LambdaQueryWrapperX<MonthPlanInfoDO>().select(MonthPlanInfoDO::getId,MonthPlanInfoDO::getName)
                .in(MonthPlanInfoDO::getId,monthIds));
        Map<Long,MonthPlanInfoDO> monthMap=monthList.stream().collect(Collectors.toMap(MonthPlanInfoDO::getId, e -> e));
        //合同信息
        List<Long> contractIds=pageResult.getList().stream().flatMap(item-> Stream.of(item.getBuyContractId(),item.getSaleContractId())).collect(Collectors.toList());
        List<ContractInfoDO> contractInfoDOList = contractInfoMapper.selectList(new LambdaQueryWrapperX<ContractInfoDO>().in(ContractInfoDO::getId,contractIds));

        Map<Long,ContractInfoDO> contractMap=contractInfoDOList.stream().collect(Collectors.toMap(ContractInfoDO::getId, e -> e));


        Map<Long, ErpProductCategoryDO> downloadMap = erpProductCategoryService.getProductCategoryMap(
                convertSet(pageResult.getList(), PlanInfoDO::getDownloadId));


        return success(BeanUtils.toBean(pageResult, PlanInfoRespVO.class, plan -> {
            MapUtils.findAndThen(monthMap, plan.getCompanyId(), cus -> plan.setCompanyName(cus.getName()));

            MapUtils.findAndThen(customerMap, plan.getSaleCustomerId(), cus -> plan.setSaleCustomerName(cus.getName()));

            MapUtils.findAndThen(contractMap, plan.getSaleContractId(), cus -> plan.setSaleContractName(cus.getName()));

            MapUtils.findAndThen(downloadMap, plan.getDownloadId(),
                    l -> plan.setDownloadName(l.getShortName()));

        }));*/
    }



    @GetMapping("/buy-info-page")
    @Operation(summary = "获得采购管理分页")
    @PreAuthorize("@ss.hasPermission('erp:buy:query')")
    public CommonResult<PageResult<PlanInfoRespVO>> getBugPlanInfoPage(@Valid PlanInfoPageReqVO pageReqVO) {
        PageResult<PlanInfoDO> pageResult = planInfoService.getPlanInfoPage(pageReqVO);


        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(PageResult.empty(pageResult.getTotal()));
        }
        List<PlanInfoRespVO> rlist=buildList(pageResult.getList(),"buy");
        PageResult<PlanInfoRespVO> rpage= BeanUtils.toBean(pageResult, PlanInfoRespVO.class);
        rpage.setList(rlist);
        return success(rpage);
    }



    @GetMapping("/export-excel")
    @Operation(summary = "导出每日计划 Excel")
    @PreAuthorize("@ss.hasPermission('lng:plan-info:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportPlanInfoExcel(@Valid PlanInfoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PlanInfoDO> list = planInfoService.getPlanInfoPage(pageReqVO).getList();

        List<PlanInfoRespVO> rlist=buildList(list,"");
        /*// 客户信息
        List<CustomerInfoDO> customerList = customerInfoMapper.selectList(new LambdaQueryWrapperX<CustomerInfoDO>().select(CustomerInfoDO::getId,CustomerInfoDO::getName));
        Map<Long,String> customerMap=customerList.stream().collect(Collectors.toMap(CustomerInfoDO::getId, CustomerInfoDO::getName));


        //月度计划
        List<Long> monthIds=list.stream().map(PlanInfoDO::getCompanyId).filter(Objects::nonNull).collect(Collectors.toList());
        List<MonthPlanInfoDO> monthList = monthPlanInfoMapper.selectList(new LambdaQueryWrapperX<MonthPlanInfoDO>().select(MonthPlanInfoDO::getId,MonthPlanInfoDO::getName)
                .in(MonthPlanInfoDO::getId,monthIds));
        Map<Long,MonthPlanInfoDO> monthMap=monthList.stream().collect(Collectors.toMap(MonthPlanInfoDO::getId, e -> e));
        //合同信息
        List<ContractInfoDO> contractInfoDOList = contractInfoMapper.selectList(new LambdaQueryWrapperX<ContractInfoDO>().select(ContractInfoDO::getId,ContractInfoDO::getName));

        Map<Long,String> contractMap=contractInfoDOList.stream().collect(Collectors.toMap(ContractInfoDO::getId, ContractInfoDO::getName));


        Map<Long, CrmProductCategoryDO> upMap = crmproductCategoryService.getProductCategoryMap(
                convertSet(list, PlanInfoDO::getUpId));

        Map<Long, ErpProductCategoryDO> downMap = erpProductCategoryService.getProductCategoryMap(
                convertSet(list, PlanInfoDO::getDownloadId));



       List<PlanInfoRespVO> rlist= BeanUtils.toBean(list, PlanInfoRespVO.class, plan -> {

           MapUtils.findAndThen(monthMap, plan.getCompanyId(), cus -> plan.setCompanyName(cus.getName()));

            MapUtils.findAndThen(customerMap, plan.getBuyCustomerId(), cus -> plan.setBuyCustomerName(cus));

            MapUtils.findAndThen(contractMap, plan.getBuyContractId(), cus -> plan.setBuyContractName(cus));


           MapUtils.findAndThen(customerMap, plan.getSaleCustomerId(), cus -> plan.setSaleCustomerName(cus));

           MapUtils.findAndThen(contractMap, plan.getSaleContractId(), cus -> plan.setSaleContractName(cus));


            MapUtils.findAndThen(upMap, plan.getUpId(),
                    l -> plan.setUpName(l.getShortName()));

            MapUtils.findAndThen(downMap, plan.getDownloadId(),
                   l -> plan.setDownloadName(l.getShortName()));
        });*/


        // 导出 Excel
        ExcelUtils.write(response, "每日计划.xls", "数据", PlanInfoRespVO.class, rlist);
    }


    @GetMapping("/export-sale-excel")
    @Operation(summary = "导出销售记录 Excel")
    @PreAuthorize("@ss.hasPermission('erp:sale:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportSalePlanInfoExcel(@Valid PlanInfoPageReqVO pageReqVO,
                                    HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PlanInfoDO> list = planInfoService.getPlanInfoPage(pageReqVO).getList();

        List<PlanInfoRespVO> rlist=buildList(list,"sale");

        // 导出 Excel
        ExcelUtils.write(response, "销售记录.xls", "数据", PlanSaleInfoRespVO.class,
                BeanUtils.toBean(rlist, PlanSaleInfoRespVO.class));
    }


    @GetMapping("/export-buy-excel")
    @Operation(summary = "导出采购记录 Excel")
    @PreAuthorize("@ss.hasPermission('erp:buy:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportBuyPlanInfoExcel(@Valid PlanInfoPageReqVO pageReqVO,
                                    HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PlanInfoDO> list = planInfoService.getPlanInfoPage(pageReqVO).getList();


        List<PlanInfoRespVO> rlist=buildList(list,"buy");


        // 导出 Excel
        ExcelUtils.write(response, "采购记录.xls", "数据", PlanBuyInfoRespVO.class,
                BeanUtils.toBean(rlist, PlanBuyInfoRespVO.class));
    }



    @GetMapping("/query-info-list")
    @Operation(summary = "查询列表")
    public CommonResult<PageResult<PlanInfoRespVO>>  queryBuyPlanInfoList(PlanInfoPageReqVO pageReqVO,
                                       HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        //默认只查询已经结算的
        pageReqVO.setStatus(1);
        List<PlanInfoDO> list = planInfoService.getPlanInfoPage(pageReqVO).getList();
        // 导出 Excel

        if (CollUtil.isEmpty(list)) {
            return success(PageResult.empty(0L));
        }
        List<PlanInfoRespVO> rlist=buildList(list,"");

        return success(new PageResult<PlanInfoRespVO>(rlist,0L));
    }






}